package lwk.thread.syn;

import java.util.ArrayList;
import java.util.List;

/**
 * @author:lwk
 * @create: 2022-08-03 19:56
 * @Description: 线程不安全的List集合
 */
public class UnsafeList {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                synchronized (list) {
                    list.add(Thread.currentThread().getName());
                }
            }).start();
        }

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(list.size());

    }
}
